
*===================================================================*
*																	*
*				Going the Last Mile 								*
*      	   		Imke Harbers & Wendy Hunter	     					*
*																	*
*===================================================================*
*				REPLICATION FILE FOR FINDEX ANALYSIS				*
*===================================================================*
* 				Figure 1, Figure 2, Table A.1						*
*===================================================================*

* Stata Version: 16.0
* IF NECESSARY: ssc install estout

***** 
* FINDEX data for 2017 needs to be downloaded directly from the Findex website: https://microdata.worldbank.org/index.php/catalog/3324
* Survey ID number: "WLD_2017_FINDEX_v02_M"; https://doi.org/10.48529/d3cf-fj47; The analysis below is based on the STATA version of the data: "WLD_2017_FINDEX_v02_M_STATA11" > "micro_world.dta"
* Save this file in the same directory as the replication files. Also download the file "wb_income_classification2017.dta" from Dataverse and save it in the same directory. 

* set working directory as appropriate
* cd "...\replication files\going the last mile"

use "micro_world.dta", clear


* data preparation
gen ID = 1 if fin48 == 1
replace ID = 0 if fin48 ~= 1

rename economycode ISO

merge m:1 ISO using "wb_income_classification2017.dta"
drop if _merge == 2
drop _merge

drop country
encode economy, generate (country)

gen pension = 1 if fin38 == 1
replace pension = 0 if fin38 ~= 1

gen socialbenefit = 1 if fin37 == 1
replace socialbenefit = 0 if fin37 ~= 1

gen benefit = 1 if pension == 1 | socialbenefit == 1
replace benefit = 0 if pension == 0 & socialbenefit == 0
label define benefit 0 "No social benefit or pension" 1 "Social benefit or pension"
label values benefit benefit

* analysis:  checking for nonlinearity in the relationship between age and ID possession
gen agecohort = 1 if age > 19 & age < 30
replace agecohort = 2 if age > 29 & age < 40
replace agecohort = 3 if age > 39 & age < 50
replace agecohort = 4 if age > 49 & age < 60
replace agecohort = 5 if age > 59 & age < 70
replace agecohort = 6 if age > 69 & age < 80
replace agecohort = 7 if age > 79 

label define Cohorts 1 "20-29" 2 "30-39" 3 "40-49" 4 "50-59" 5 "60-69" 6 "70-79" 7 "80+" 
label values agecohort Cohorts

logit ID i.agecohort i.country if wb_income ~= "H"
margins agecohort
marginsplot
contrast p.agecohort 


** Figure 1
logit ID c.age##c.age female i.country if wb_income ~= "H" & age > 20, vce(cluster country) noemptycells 
estimates store m1
margins, at (age = (21(1)99))
marginsplot, recastci(rspike) xlabel(21 30 40 50 60 70 80 90 99) xtick (25 35 45 55 65 75 85 95) xtitle("Age", margin(medium)) ylabel (.75 .8 .85 .9 .95, angle(0)) ytitle ("ID Posession (Predicted)") title ("")
graph export "figure 1.png", as(png) name("Graph") replace


** Figure 2
logit ID c.age##c.age##benefit female i.country if wb_income ~= "H" & age > 20, vce(cluster country) noemptycells 
estimates store m2
margins, at (age = (21(1)99) benefit = (0 1))
marginsplot, recastci(rspike) xlabel(21 30 40 50 60 70 80 90 99) xtick (25 35 45 55 65 75 85 95) xtitle("Age", margin(medium)) ylabel (.75 .8 .85 .9 .95, angle(0)) ytitle ("ID Posession (Predicted)") title ("")
graph export "figure 2.png", as(png) name("Graph") replace

** Table A.1
esttab m1 m2 using tablea1.tex, label

